//
//  BKXueKeViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/2.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKXueKeViewController.h"
#import "BKZhaoShengTableViewCell.h"
#import "BKColleageViewModel.h"
#import <MBProgressHUD.h>

static NSString *xueke = @"xueke";
@interface BKXueKeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, copy) NSArray *dataArray;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@end

@implementation BKXueKeViewController
- (IBAction)p_back:(id)sender {
    [_delegate dismiss];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BKZhaoShengTableViewCell class]) bundle:nil] forCellReuseIdentifier:xueke];
    
    _tableView.separatorColor = [UIColor clearColor];
    __weak BKXueKeViewController *weakSelf = self;
    
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:hud];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = @"正在加载学科信息";
    [hud show:YES];
    
    [BKColleageViewModel xuekeWithCid:_cid success:^(NSArray *array) {
        weakSelf.dataArray = array;
        [hud hide:YES];
    } failure:^(NSString *message) {
        [hud hide:YES];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
        [alertView show];
    }];
    
    
    _titleLabel.text = _name;

}


- (void)setName:(NSString *)name{
    _name = name;
    _titleLabel.text = name;
}
- (void)setDataArray:(NSArray *)dataArray{


    _dataArray = dataArray;
    [_tableView reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    BKZhaoShengTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:xueke];
    if (indexPath.row==0) {
        cell.zhuanye.text = @"学科名";
        cell.jihua.text = @"级别";
    }else{
    
        cell.zhuanye.text = _dataArray[indexPath.row-1][@"subject"];
        cell.jihua.text = _dataArray[indexPath.row-1][@"title"];
        
    }
    
    if (indexPath.row%2!=0) {
        cell.backgroundColor = [UIColor clearColor];
    }else{
    
        cell.backgroundColor = [UIColor colorWithRed:0.906 green:0.965 blue:0.980 alpha:1.000];
    }
    return cell;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [_dataArray count]+1;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 10;
}
@end
